//
//  CommonNewsItemCell.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/19.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "CommonNewsItemCell.h"

#import "ArticleListData.h"

@interface CommonNewsItemCell ()

/// viewModle
@property (nonatomic, readwrite, strong) CommonNewsItemViewModel *viewModel;

/// IBOutlet
@property (weak, nonatomic) IBOutlet UILabel* titleLabel;
@property (weak, nonatomic) IBOutlet UILabel* tagLabel;
@property (weak, nonatomic) IBOutlet UILabel* timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView* aImgView;

@end

@implementation CommonNewsItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //iOS11版本以上,自定义删除按钮高度方法:
    if ([[UIDevice currentDevice].systemVersion doubleValue] < 11.0f)
    {
        for (UIView *subView in self.subviews)
        {
            if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")])
            {
                UIView *confirmView = (UIView *)[subView.subviews firstObject];
                
                //改背景颜色
                //            confirmView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"l12_2_req_btn_bg_02"]];
                confirmView.backgroundColor = UIColorHex(#f2f2f2);
                
                CGFloat imgWidth = confirmView.frame.size.width - 16.0f;
                
                UIImageView *imageView = [[UIImageView alloc] init];
                imageView.image = [UIImage imageNamed:@"icon_lajitong"];
                imageView.frame = CGRectMake(8.0f, (confirmView.frame.size.height - imgWidth)/2.0f, imgWidth, imgWidth);
                [confirmView addSubview:imageView];
                
                for(UIView *sub in confirmView.subviews)
                {
                    //修改字的大小、颜色，这个方法可以修改文字样式
                    //                if ([sub isKindOfClass:NSClassFromString(@"UIButtonLabel")]) {
                    //
                    //                    UILabel *deleteLabel=(UILabel *)sub;
                    //                    // deleteLabel.backgroundColor = [UIColor redColor];
                    //
                    //                    //改删除按钮的字体大小
                    //
                    //                    deleteLabel.font = [UIFont jk_systemFontOfPxSize:24];
                    //                    deleteLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
                    //
                    //                    // 改删除按钮的文字
                    //
                    //                    deleteLabel.text=@"删除";
                    //
                    //                }
                    
                    //添加图片
//                    if ([sub isKindOfClass:NSClassFromString(@"UIView")])
//                    {
//                        CGFloat imgWidth = confirmView.frame.size.width - 16.0f;
//
//                        UIView *deleteView = sub;
//                        UIImageView *imageView = [[UIImageView alloc] init];
//                        imageView.image = [UIImage imageNamed:@"icon_lajitong"];
////                        imageView.frame = CGRectMake(CGRectGetMaxX(sub.frame) - 58, -5, 44, 44);
//                        imageView.frame = CGRectMake(0, 0, imgWidth, imgWidth);
//                        [deleteView addSubview:imageView];
//                    }
                }
                
                break;
            }
        }
    }
}

#pragma mark - bind data
- (void)bindViewModel:(CommonNewsItemViewModel *)viewModel
{
    self.viewModel = viewModel;
    
    self.titleLabel.text = self.viewModel.title;
    self.tagLabel.text = self.viewModel.tag;
    self.timeLabel.text = self.viewModel.time;
    
    if (self.viewModel.imgurl && [self.viewModel.imgurl isNotBlank])
    {
        [self.aImgView yy_setImageWithURL:[NSURL URLWithString:self.viewModel.imgurl] placeholder:MHImageNamed(@"placeholderLogo")];
    }
    //    [self.aImgView yy_setImageWithURL:[NSURL URLWithString:curUserData.icon] placeholder:MHImageNamed(@"placeholderLogo")];
}

@end
